package com.hs.system.api.fallback;

import com.hs.common.core.domain.Result;
import com.hs.system.api.entity.User;
import com.hs.system.api.feign.RemoteSystemService;
import com.hs.system.api.model.LoginUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 用户服务降级处理
 */
@Component
public class RemoteSystemFallbackFactory implements FallbackFactory<RemoteSystemService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteSystemFallbackFactory.class);

    @Override
    public RemoteSystemService create(Throwable throwable) {
        log.error("用户服务调用失败:{}", throwable.getMessage());
        return new RemoteSystemService() {
            @Override
            public Result<LoginUser> getUserInfo(String username, String source) {
                System.out.println("服务降级触发回调");
                return Result.fail("用户服务暂不可用:" + throwable.getMessage());
            }

            @Override
            public Result<Boolean> registerUserInfo(User sysUser, String source) {
                return Result.fail("注册用户失败:" + throwable.getMessage());
            }
        };
    }
}
